package com.mowh.multithreading.future;

import java.util.concurrent.Callable;

/**
 * @author mowh1gd
 * @create 2023/11/24 16:53
 */
public class HostCallable {
    public Data request(final int count, final char c) {
        System.out.println("   request(" + count + ", " + c + ")  BEGIN");
        FutureDataTask future = new FutureDataTask(//创建FutureData实例
                new Callable<RealData>() {
                    @Override
                    public RealData call() throws Exception {
                        return new RealData(count, c);//只关注如何生成数据，生成数据后给FutureData的realData属性赋值的操作（即setter）已被抽象化
                    }
                }
        );
        new Thread(future).start();//开启新线程去生成数据（耗时）
        System.out.println("   request(" + count + ", " + c + ")  END");
        return future;
    }
}
